package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Type;

public class CopyDemo1 {
    public static void main(String[] args) throws IOException {
        /*
        FileInputStream fis = new FileInputStream("xn.jpg");
        FileOutputStream fos = new FileOutputStream("xn1.jpg");
        Long start = System.currentTimeMillis();
        byte[] data=new byte[1024*10];//10kb
        while(fis.read(data)!=-1){
            fos.write(data);//此方式是一段字节的读取,但结果可能超实际字节数
        }
        Long end = System.currentTimeMillis();
        System.out.println("复制完毕!"+(end-start)+"ms");
        fis.close();
        fos.close();
         */
        FileInputStream fis = new FileInputStream("xn.jpg");
        FileOutputStream fos = new FileOutputStream("xn1.jpg");
        Long start = System.currentTimeMillis();
        byte[] data=new byte[1024*10];//10kb
        int len;
        while((len=fis.read(data))!=-1){
            fos.write(data,0,len);//重载,此方式可以读取实际字节数
        }
        Long end = System.currentTimeMillis();
        System.out.println("复制完毕!"+(end-start)+"ms");
        fis.close();
        fos.close();


    }
}
